
public class HeadManufacturer extends Manufacturer{

	public HeadManufacturer(int id) {
		setName("HeadManufacturer-" + id);
	}
	
	public void run(){
		msg("HeadManufacturer Thread has Started Running");
		while(!factoryAboutToStopOperation){
			if (isSurplus)
				haltProduction();
			produceHead();
			deliverHead();
		}
	}

	private void haltProduction() {
		try {
			msg("Production HALTED due to Surplus");
			sleep(HALT_TIME);
			isSurplus = false;
		} catch (InterruptedException e) {
		}		
	}
	
	private void produceHead() {
		int randomNum;
		randomNum = PRODUCTION_TIME_MIN + (int)(Math.random() * ((PRODUCTION_TIME_MAX - PRODUCTION_TIME_MIN) + 1));
		try {
			sleep(randomNum);
			msg("Head Produced");
		} catch (InterruptedException e) {
		}
	}

	private void deliverHead() {
		Truck t = new Truck();
		msg("Start truck thread to deliver Head (truck #"+t.truckId+")");
		t.start();
		t.setPartType("HEAD");
	}
}
